/**
 * Copyright:Copyright(c)2014-2017
 * Company:厦门市易致达物联网科技有限公司
 * @version 1.0
 */
package shop.controller.front.record;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import shop.core.FrontBaseController;
import shop.core.Services;
import shop.core.common.bean.JSONResult;
import shop.services.front.account.bean.Account;
import shop.services.front.record.RecordService;
import shop.services.front.record.bean.Record;
import shop.services.manage.system.bean.User;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**   
 * @类名称：RecordController
 * @创建人：Ltz   
 * @创建时间：2017-08-12 上午10:16:33
 * @版本号：1.0
 * @描述：     
 */
@Controller
@RequestMapping("/front/record")
public class RecordController extends FrontBaseController<Record> {
    @Resource
    private RecordService recordService;
    @Override
    public Services<Record> getService() {
        return recordService;
    }

    /**
     * 查询交易记录
     *
     * @return
     * @throws Exception
     */
    @Override
    @RequestMapping("/selectAllList")
    @ResponseBody
    public JSONResult selectAllList(HttpServletRequest request, @ModelAttribute("record") Record record) throws Exception {
        Account account = (Account) request.getSession().getAttribute("accountInfo");
        User user = (User) request.getSession().getAttribute("userInfo");
        jsonResult = new JSONResult();
        if(account!=null){
            record.setUserID(account.getId());
            record.setUserType("1");
            List<Record> rsList = getService().selectList(record);
            jsonResult.setData(rsList);
            return jsonResult;
        }else if(user!=null){
            record.setUserID(user.getId());
            record.setUserType("2");
            List<Record> rsList = getService().selectList(record);
            jsonResult.setData(rsList);
            return jsonResult;
        }else{
            jsonResult.setSuccess(false);
            jsonResult.setMessage("您还未登陆，无法查看交易记录！");
            return jsonResult;
        }
    }
}
